﻿using InhollandAir.App_Code;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace InhollandAir
{
    public partial class logout : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            Dictionary<string, User> activeUsers = (Dictionary<string, User>)Application["ActiveUsers"];
            if (activeUsers.ContainsKey(Session.SessionID))
            {
                int id = 0;
                try
                {
                    id = activeUsers[Session.SessionID].id;
                    activeUsers.Remove(Session.SessionID);
                    Application["ActiveUsers"] = activeUsers;

                    SessionIDManager Manager = new SessionIDManager();

                    string NewID = Manager.CreateSessionID(Context);
                    bool redirected = false;
                    bool IsAdded = false;
                    Manager.SaveSessionID(Context, NewID, out redirected, out IsAdded);
                    Logging.WriteActivity("UserID: " + id + " logged out.");
                }
                catch (Exception ex)
                {
                    //log exception
                    Logging.WriteError(ex.Message + ". UserID: " + id);
                    Response.Write(ex.ToString());
                }
            }
            Response.Redirect("Index.aspx");
        }
    }
}